#ifndef NORMALDEFECTMODELS_H
#define NORMALDEFECTMODELS_H
#include <QObject>
#include <QList>
#include <QQmlListProperty>




/**
 *
 *  该Type存储json读取的对象 用于和缺陷信息进行比较
 *
 * */



/**
 * @brief 结构如下
 *   DefectStandrd : [
 *                      Name: "",
 *                      Length,
 *                      width: 0,
 *                      times: 0,
 *                  ]
 */
class DefectStandrd :public QObject{
    Q_OBJECT

public:
    explicit DefectStandrd(QObject *parent = nullptr): QObject(parent){};
    DefectStandrd(QString n,int l,int w, int t):Name(n),Length(l),Width(w),times(t){};

    QString GetName()const{ return this->Name; }
    void SetName(const QString &str){ this->Name = str; }

    int GetLength()const { return Length; }
    void SetLength(const int & l) { this->Length = l; }

    int GetWidth()const { return this->Width; }
    void SetWidth(const int & w){ this->Width = w; }

    int GetTimes()const { return this->times; }
    void SetTimes(const int & t) { this->times =t; }

    bool operator==(const DefectStandrd &other) const{
        return (Name.compare(other.GetName()) == 0);
    }

private:
    QString Name;//等级名称
    int Length; //缺陷长度 或者 钢板总长 或者边部
    int Width; //宽度
    int times; //次数 频率
};


/**
 * @brief 结构如下
 *   DefectLvDetectWrapper : {
 *                               DefectStandrd : [...],
 *                               DefectName : ""
 *                           }
 */
class DefectLvDetectWrapper: public QObject{
    Q_OBJECT

public:
    explicit DefectLvDetectWrapper(QObject *parent = nullptr) : QObject(parent){}

public:
    QString GetDefectName()const { return this->DefectName; }
    void SetDefectName(const QString & defectName){ this->DefectName = defectName; }


signals:
    void DefectStandrdListChanged();

public:
    QList<DefectStandrd *> m_DefectStandrdList;


    void addDefectStandrd(DefectStandrd * d){
        this->m_DefectStandrdList.append(d);
    }



    //根据等级名称进行查询
    DefectStandrd*  findElementByName(QString name){
        foreach (DefectStandrd * standrd, this->m_DefectStandrdList) {
            if( (standrd->GetName().compare(name) == 0)){
                return standrd;
            }
        }
        return nullptr;

    };

    bool operator==(const DefectLvDetectWrapper &other) const{
        return (this->DefectName.compare(other.GetDefectName())==0);
    }

private:
    QString DefectName; //缺陷名称
};



/**
 * @brief 结构如下
 *   NormalDetectWrapper : {
 *                               DefectLvDetectWrapper : [...],
 *                               SteelType : ""
 *                         }
 */
class NormalDetectWrapper : public QObject{
    Q_OBJECT
public:
    QString GetSteelType()const{ return this->SteelType; }
    void SetSteelType(const QString &type){ this->SteelType = type; };

    void AddDefectLvDetect(DefectLvDetectWrapper * d){
        this->m_DefectLvDetectWrapperList.append(d);
    }


signals:
    void DefectLvDetectChanged();

public:
    QString SteelType;

    QList<DefectLvDetectWrapper*> m_DefectLvDetectWrapperList;

    bool operator==(const NormalDetectWrapper &other) const{
        return (this->SteelType.compare(other.GetSteelType()) == 0);
    }
};



/**
 * @brief 按长,宽，面积 次数来判级的缺陷
 */
class NormalDetectBase : public QObject{
    Q_OBJECT
public:

    //根据缺陷名称和钢种查找指定缺陷条件
    DefectLvDetectWrapper* findDefectByName(QString DefectName,QString steelType){

        NormalDetectWrapper normal;
        normal.SetSteelType(steelType);

        DefectLvDetectWrapper d;
        d.SetDefectName(DefectName);

        for (int i = 0; i < this->m_NormalDetectWrapperList.length(); ++i) {
            if(*this->m_NormalDetectWrapperList[i] == normal){
                for (int j = 0; j < m_NormalDetectWrapperList[i]->m_DefectLvDetectWrapperList.length(); ++j) {
                    if(*m_NormalDetectWrapperList[i]->m_DefectLvDetectWrapperList[j] == d){
                        return m_NormalDetectWrapperList[i]->m_DefectLvDetectWrapperList[j];
                    }
                }
            }

        }
        return nullptr;
    };


    void AddNormalDetectWrapper(NormalDetectWrapper * warpper){
        this->m_NormalDetectWrapperList.append(warpper);
    }




signals:
    void NormalDetectWrapperListChanged();
public:
    QList<NormalDetectWrapper *> m_NormalDetectWrapperList;
};



/**
 * @brief 只按长度来判级的缺陷
 */
class VerticalLengthDetectBase : public NormalDetectBase{
    Q_OBJECT

};



/**
 * @brief 只按缺陷多少米内出现多少处来判级的缺陷
 */
class FrequencyDetectBase :public NormalDetectBase{
    Q_OBJECT
};



/**
 * @brief 存在就出现降级的缺陷
 */
class DirectLevelBase : public NormalDetectBase{
    Q_OBJECT
};



/**
 * @brief 距离边部降级的缺陷
 */
class BesideDetectBase : public NormalDetectBase{
    Q_OBJECT
};



#endif // NORMALDEFECTMODELS_H
